# pylint: disable-msg=W0232
"""
@author: Sergiy Tsymbalyuk
"""

from pylons.i18n import lazy_ugettext as _

from sqlalchemy import Column, ForeignKey, Table
from sqlalchemy.types import Integer, String, Text, Date, Enum, Boolean
from sqlalchemy.orm import relation, backref

from hrms.model.meta import Base
from hrms.model.person import Employee

from chowa.model.auth import User
from chowa.model.organization import Institution, District, Division

__all__ = ['School',
           'SchoolName',
           'Specialty',
           'Qualification',
           'Education',
           'Stage',
           'Training']

#### EDUCATION ####

class School(Base):
    __tablename__ = 'hrms_education_school'
    
    id = Column(Integer, primary_key=True)
    
    full_name = Column(String(255), info={'verbose': _('Full name')})
    short_name = Column(String(20), info={'verbose': _('Short name')})
    locality = Column(String(100))
    
    def __unicode__(self):
        return self.full_name


class SchoolName(Base):
    __tablename__ = 'hrms_education_school_name'
    
    id = Column(Integer, primary_key=True)
    name = Column(String(255), info={'verbose': _('Object|Name')})
    initiated = Column(Date, info={'verbose': _('Initiated')})
    outdated = Column(Date, info={'verbose': _('Outdated')})
    school_id = Column(Integer, ForeignKey(School.id))
    
    school = relation(School, backref='names')
    
    def __unicode__(self):
        return self.name


class Specialty(Base):
    __tablename__ = 'hrms_education_specialty'
    
    id = Column(Integer, primary_key=True)
    name = Column(String(100), info={'verbose': _('Object|Name')})
    school_id = Column(Integer, ForeignKey(School.id), info={'verbose': _('School')})
    
    school = relation(School, backref='specialties')
    
    def __unicode__(self):
        return self.name


class Qualification(Base):
    __tablename__ = 'hrms_education_qualification'
    
    id = Column(Integer, primary_key=True)
    name = Column(String(100), unique=True)
    
    def __unicode__(self):
        return self.name


class Stage(Base):
    __tablename__ = 'hrms_education_stage'
    
    id = Column(Integer, primary_key=True)
    name = Column(String(100), unique=True, info={'verbose': _('Object|Name')})
    
    def __unicode__(self):
        return self.name


class Education(Base):
    __tablename__ = 'hrms_education'
    
    id = Column(Integer, primary_key=True)
    specialty_id = Column(Integer, ForeignKey(Specialty.id), info={'verbose': _('Specialty')})
    qualification_id = Column(Integer, ForeignKey(Qualification.id), info={'verbose': _('Qualification')})
    stage_id = Column(Integer, ForeignKey(Stage.id), info={'verbose': _('Stage')})
    diploma_series = Column(String(10), info={'verbose': _('Diploma series')})
    diploma_no = Column(Integer, info={'verbose': _('Diploma number')})
    graduated = Column(Date, info={'verbose': _('Graduated')})
    employee_id = Column(Integer, ForeignKey(Employee.id), info={'verbose': _('Employee')})
    
    employee = relation(Employee)
    specialty = relation(Specialty)
    stage = relation(Stage)


class Training(Base):
    __tablename__ = 'hrms_education_training'
    
    id = Column(Integer, primary_key=True)
    school_id = Column(Integer, ForeignKey(School.id), info={'verbose': _('School')})
    graduated = Column(Date, info={'verbose': _('Graduated')})
    employee_id = Column(Integer, ForeignKey(Employee.id), info={'verbose': _('Employee')})
    description = Column(String(255), info={'verbose': _('Description')})
    
    employee = relation(Employee)
    school = relation(School)
